<template>
  <div class="card">
    <slot name="header">
      <div class="card__header">
        <slot name="header-left"></slot>

        <slot name="header-title">
          <div class="title">{{ title }}</div>
        </slot>

        <slot name="header-center"></slot>

        <slot name="header-tag">
          <template v-if="showTag">
            <div
              v-if="tagHtml"
              class="tag"
              :style="{ background: tagBgColor, color: tagTextColor }"
              v-html="tagHtml"
            />

            <div
              v-else
              class="tag"
              :style="{ background: tagBgColor, color: tagTextColor }"
            >
              {{ tagText }}
            </div>
          </template>
        </slot>

        <slot name="header-right"></slot>
      </div>
    </slot>

    <slot>
      <div class="card__body">
        <div class="filed" v-for="(item, index) in filedList" :key="index">
          <div class="filed__label">
            <slot name="filed-label"> {{ item.label }}：</slot>
          </div>

          <div class="filed__value">
            <slot name="filed-value">
              <ArkDesensitized
                v-if="item.desensitizedValue"
                :value="item.value"
                :desensitized-value="item.desensitizedValue"
              />

              <van-text-ellipsis
                v-else
                :content="item.value"
                expand-text="展开"
                collapse-text="收起"
                @click-action.stop
              />
            </slot>
          </div>
        </div>
      </div>
    </slot>
  </div>
</template>

<script lang="js">
import {defineComponent} from "vue";
import ArkDesensitized from "@/components/base-component-v1/ark-desensitized/ArkDesensitized.vue";

export default defineComponent({
  name: "InfoCardDefault",
  components: {ArkDesensitized},
  props: {
    title: String,
    showTag: {
      type: Boolean,
      default: true
    },
    tagText: String,
    tagHtml: String,
    tagBgColor: {
      type: String,
      default: '#cbcbcb'
    },
    tagTextColor: {
      type: String,
      default: '#fff'
    },
    /**
     * - label：名
     * - value：值
     * - desensitizedValue：脱敏值
     */
    filedList: Array
  },
  data() {
    return {};
  },
});
</script>

<style scoped lang="scss">
.card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px 0 rgba(45, 90, 250, 0.25);
  padding: 12px;
  display: flex;
  flex-direction: column;
  row-gap: 14px;

  &__header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    column-gap: 10px;
  }

  &__body {
    display: flex;
    flex-direction: column;
    row-gap: 6px;
  }
}

.title {
  font-size: 16px;
  line-height: 25px;
  font-weight: bold;
  color: #333;
}

.tag {
  width: 52px;
  height: 25px;
  border-radius: 4px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 12px;
  line-height: normal;
  font-weight: bold;
  color: #fff;
}

.filed {
  display: flex;
  align-items: start;

  &__label {
    flex-shrink: 0;
    font-size: 10px;
    line-height: 20px;
    font-weight: normal;
    color: #333;
  }

  &__value {
    font-size: 12px;
    line-height: 20px;
    font-weight: bold;
    color: #333;
  }
}
</style>
